package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.AdminMapper;
import com.xxxx.server.mapper.LectureinfoMapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.Lectureinfo;
import com.xxxx.server.pojo.Lecturereverse;
import com.xxxx.server.pojo.RespPageBean;
import com.xxxx.server.service.ILectureinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LT
 * @since 2022-02-27
 */
@Service
public class LectureinfoServiceImpl extends ServiceImpl<LectureinfoMapper, Lectureinfo> implements ILectureinfoService {

    @Autowired
    private LectureinfoMapper lectureinfoMapper;
    /**
     * 通过关键字搜索讲座信息
     * @param keywords
     * @return
     */
    @Override
    public List<Lectureinfo> getAllLectureInfoByKeyWords(String keywords) {

        return lectureinfoMapper.getAllLectureInfoByKeyWords(keywords);


    }
    /**
     * 获取所有分页信息并分页显示
     * @param currentPage
     * @param size
     * @param lectureinfo
     * @return
     */
    @Override
    public RespPageBean getAllLectureInfoByPage(Integer currentPage, Integer size, Lectureinfo lectureinfo) {
       //开启分页 Page类型选择mybatis plus extends
     if(lectureinfo.getName()==null)
     {
         lectureinfo.setName("");
     }

        Page<Lectureinfo> page= new Page(currentPage,size);

        IPage<Lectureinfo> LectureInfoByPage = lectureinfoMapper.getAllLectureInfoByPage(page, lectureinfo);
        //参数为总数，list
        RespPageBean respPageBean=new RespPageBean(LectureInfoByPage.getTotal(),LectureInfoByPage.getRecords());
        return respPageBean;
    }

    /**
     * 根据id查询讲座信息,方便导出
     * @param id
     * @return
     */
    @Override
    public List<Lectureinfo> downloadsLectureInfo(Integer id) {
        return lectureinfoMapper.downloadsLectureInfo(id);
    }

    /**
     * 通过讲座id查询讲座信息
     *
     * @param lectureId
     * @return
     */
    @Override
    public List<Lectureinfo> getAllLectureInfoByLectureId(Integer lectureId) {
        return lectureinfoMapper.getAllLectureInfoByLectureId(lectureId);
    }
}
